package Client

import (
	"errors"
	"fmt"
	internalType "gateway/internal/types"
	"gateway/websocket/logic"
	"gateway/websocket/resp"
	"gateway/websocket/types"
)

func GetTypeLogic(req types.RequestMessage, c *Client) (types.ServiceMessage, error) {
	var (
		d = types.ServiceMessage{}
	)

	if req.Data == "" {
		return d, errors.New("请传入参数")
	}

	d.Type = req.Type
	switch req.Type {
	case types.SysHi:
		data, err := types.GetMessageData[types.GetReqData](req.Data)
		if err != nil {
			return d, err
		}
		err = logic.TestBackDAta(data, &d)
		if err != nil {
			return d, err
		}
		return d, nil
	case types.SysDevice:

		data, err := types.GetMessageData[internalType.ClientDevice](req.Data)
		if err != nil {
			return d, err
		}
		fmt.Print(123)
		fmt.Print(data)
		//err = logic.SetClientDeviceInfo(data, &d, c)
		c.DeviceInfo = data
		resp.RespMessages(&d)
		return d, nil
	case types.SysDeviceTasks:
		fmt.Println(req.Data)
		data, err := types.GetMessageData[internalType.Task](req.Data)
		if err != nil {
			return d, err
		}
		c.Tasks = data
		resp.RespMessages(&d)
		return d, nil
	default:
		d.Type = types.SysErr
		return d, errors.New("请传入正确的指令")
	}

}
